Hausuebung FotoForum Tests
Current file: /home/estudydev/workspace/eStudy_svn/web/pdf/classes/class.pdfphotogallery.inc.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 8 / 8
96.03 %96.03%
96.03% 145 / 151
 
PdfPhotogallery
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 8 / 8
96.03 %96.03%
96.03% 145 / 151
 public function __construct()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 7 / 7
 public function printOnePhoto($id)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 7 / 7
 public function printPhotoalbum($id)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 11 / 11
 public function printAllPhotoalbum()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 7 / 7
 private function postToDoc($data)
100.00 %100.00%
100.00% 1 / 1
92.77 %92.77%
92.77% 77 / 83
 private function doIt($row, $pdf)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 24 / 24
 public function checkCourse($row)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 6 / 6
 public function checkData($data)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 6 / 6


       1                 : <?php                                                                                                           
       2                 : /*--------------------------------------------------------------------------+                                   
       3                 :  This file is part of eStudy.                                                                                   
       4                 :  pdf/build.php                                                                                                  
       5                 :  - Modulgruppe:  pdf                                                                                            
       6                 :  - Beschreibung: Export von Mitteilungen, Forum & Pers�nlichen Nachrichten.                                   
       7                 :  - Version:      3.0, 20/02/09                                                                                  
       8                 :  - Autor(en):    Alexander Ehnes <alexander.ehnes@mni.fh-giessen.de>                                            
       9                 :                                                                                                                 
      10                 :  +---------------------------------------------------------------------------+                                  
      11                 :  This program is free software; you can redistribute it and/or                                                  
      12                 :  modify it under the terms of the GNU General Public License                                                    
      13                 :  as published by the Free Software Foundation; either version 2                                                 
      14                 :  of the License, or any later version.                                                                          
      15                 :  +---------------------------------------------------------------------------+                                  
      16                 :  This program is distributed in the hope that it will be useful,                                                
      17                 :  but WITHOUT ANY WARRANTY; without even the implied warranty of                                                 
      18                 :  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                                  
      19                 :  GNU General Public License for more details.                                                                   
      20                 :  You should have received a copy of the GNU General Public License                                              
      21                 :  along with this program; if not, write to the Free Software                                                    
      22                 :  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                                    
      23                 :  +--------------------------------------------------------------------------*/                                  
      24                 : /**                                                                                                             
      25                 :  * Exportdialog des Moduls PDF                                                                                  
      26                 :  * @package eStudy.pdf                                                                                          
      27                 :  * @version 3.0, 20/02/09                                                                                       
      28                 :  * @author Alexander Ehnes <alexander.ehnes@mni.fh-giessen.de>                                                  
      29                 :  */                                                                                                             
      30                 : require_once (PATH_TO_ROOT ."photogallery/admin/classes/class.gallerysettings.inc.php");                        
      31                 : require_once (PATH_TO_ROOT . 'common/settings.inc.php');                                                        
      32                 : require_once (PATH_TO_ROOT . 'common/classes/tcpdf/config/lang/eng.php');                                       
      33                 : require_once (PATH_TO_ROOT . 'common/classes/tcpdf/tcpdf.php');                                                 
      34                 : require_once (PATH_TO_ROOT . "common/classes/class.bbcode.inc.php");                                            
      35                 : require_once ("class.pdfstyles.inc.php");                                                                       
      36                 : require_once ("class.createpdf.inc.php");                                                                       
      37                 :                                                                                                                 
      38                 : class PdfPhotogallery extends Pdfstyles {                                                                       
      39                 :     private $isBoard = false;                                                                                   
      40                 :     private $boardDesc;                                                                                         
      41                 :     private $lastBoardDesc;                                                                                     
      42                 :     private $firstPageWritten = false;                                                                          
      43                 :     private $lastBoard;                                                                                         
      44                 :     private $translate;                                                                                         
      45                 :                                                                                                                 
      46                 : public function __construct() {                                                                                 
      47               5 :         global $db;                                                                                             
      48               5 :         $this->db = $db;                                                                                        
      49               5 :         $translate = getTranslate("pdf");                                                                       
      50               5 :         $this->translate = $translate;                                                                          
      51               5 :         $locale = new Zend_Locale();                                                                            
      52               5 :         $this->locale = $locale;                                                                                
      53               5 :     }                                                                                                           
      54                 :                                                                                                                 
      55                 : public function printOnePhoto($id) {                                                                            
      56               1 :         $id = Data::toMYSQL($id, false);                                                                        
      57               1 :         $query = "SELECT t.threadid,                                                                            
      58                 :                          t.threadtopic,                                                                         
      59                 :                          u.Vorname,                                                                             
      60                 :                          u.Nachname,                                                                            
      61                 :                          p.posttime,                                                                            
      62                 :                          p.posttext,                                                                            
      63                 :                          p.postfilename,                                                                        
      64                 :                          p.postfilesavename,                                                                    
      65                 :                          b.boardid,                                                                             
      66                 :                          b.boardname,                                                                           
      67                 :                          b.categoryid                                                                           
      68                 :                    FROM forum_board as b,                                                                       
      69                 :                             forum_thread as t,                                                                  
      70                 :                             forum_post as p,                                                                    
      71                 :                             user as u                                                                           
      72                 :                    WHERE b.boardid = t.boardid                                                                  
      73               1 :                      and p.postid='$id'                                                                         
      74                 :                      and p.threadid=t.threadid                                                                  
      75               1 :                      and p.userID = u.ID";                                                                      
      76               1 :         $post = $this->db->get_results($query, ARRAY_A);                                                        
      77               1 :         $this->postToDoc($post);                                                                                
      78               1 :     }                                                                                                           
      79                 :                                                                                                                 
      80                 : public function printPhotoalbum($id) {                                                                          
      81               1 :         $id = Data::toMYSQL($id, false);                                                                        
      82               1 :         $query = "SELECT t.threadid,                                                                            
      83                 :                          t.threadtopic,                                                                         
      84                 :                          u.Vorname,                                                                             
      85                 :                          u.Nachname,                                                                            
      86                 :                          p.posttime,                                                                            
      87                 :                          p.posttext,                                                                            
      88                 :                          p.postfilename,                                                                        
      89                 :                          p.postfilesavename,                                                                    
      90                 :                          b.boardid,                                                                             
      91                 :                          b.boardname,                                                                           
      92                 :                          b.categoryid                                                                           
      93                 :                   FROM forum_board as b,                                                                        
      94                 :                          forum_thread as t,                                                                     
      95                 :                          forum_post as p,                                                                       
      96                 :                          user as u                                                                              
      97                 :                   WHERE b.boardid = t.boardid                                                                   
      98                 :                       and p.threadid=t.threadid                                                                 
      99               1 :                       and t.boardid='$id'                                                                       
     100                 :                       and p.userID = u.ID                                                                       
     101                 :                   ORDER BY b.boardorder,                                                                        
     102                 :                              t.threadtopic,                                                                     
     103               1 :                              p.posttime";                                                                       
     104               1 :         $posts = $this->db->get_results($query, ARRAY_A);                                                       
     105               1 :         $this->isBoard = true;                                                                                  
     106               1 :         $this->boardDesc = $this->db->get_var(                                                                  
     107                 :                                              "SELECT boarddescription                                           
     108                 :                                               FROM forum_board                                                  
     109               1 :                                               WHERE boardid='" . Data::toMYSQL($id) . "'"                       
     110               1 :                                               );                                                                
     111               1 :         $this->postToDoc($posts);                                                                               
     112               1 :     }                                                                                                           
     113                 :                                                                                                                 
     114                 : public function printAllPhotoalbum() {                                                                          
     115               1 :         $courseID = Data::toMYSQL($_SESSION['course'], false);                                                  
     116               1 :         $query = "SELECT t.threadid,                                                                            
     117                 :                          t.threadtopic,                                                                         
     118                 :                          u.Vorname,                                                                             
     119                 :                          u.Nachname,                                                                            
     120                 :                          p.posttime,                                                                            
     121                 :                          p.posttext,                                                                            
     122                 :                          p.postfilename,                                                                        
     123                 :                          p.postfilesavename,                                                                    
     124                 :                          b.boardid,                                                                             
     125                 :                          b.boardname,                                                                           
     126                 :                          b.categoryid,                                                                          
     127                 :                          b.boarddescription                                                                     
     128                 :                    FROM forum_board as b,                                                                       
     129                 :                          forum_thread as t,                                                                     
     130                 :                          forum_post as p,                                                                       
     131                 :                          user as u                                                                              
     132               1 :                    WHERE b.categoryid = '$courseID'                                                             
     133                 :                      and b.boardid = t.boardid                                                                  
     134                 :                      and p.threadid = t.threadid                                                                
     135                 :                      and p.userID = u.ID                                                                        
     136                 :                    ORDER BY b.boardorder,                                                                       
     137                 :                             t.threadtopic,                                                                      
     138               1 :                             p.posttime";                                                                        
     139               1 :         $posts = $this->db->get_results($query, ARRAY_A);                                                       
     140               1 :         $this->postToDoc($posts);                                                                               
     141               1 :     }                                                                                                           
     142                 :                                                                                                                 
     143                 :     private function postToDoc($data) {                                                                         
     144               3 :         $newPdf = new createPdf();                                                                              
     145               3 :         $pdf = $newPdf->newPdf();                                                                               
     146               3 :         extract($pdf);                                                                                          
     147               3 :         $pdf->AddPage();                                                                                        
     148               3 :         $prevThreadId = 0;                                                                                      
     149               3 :         $this->checkData($data);                                                                                
     150                 :                                                                                                                 
     151               3 :         if ($_SESSION['course'] == 0) {                                                                         
     152               1 :             $course = 'Foyer';                                                                                  
     153               1 :             $courseType = '';                                                                                   
     154               1 :         } else {                                                                                                
     155               3 :             $courseData = $this->db->get_results(                                                               
     156                 :                                         "SELECT Name, Type                                                      
     157                 :                                          FROM courses                                                           
     158               3 :                                          WHERE ID='" . Data::toMYSQL($_SESSION['course']) . "'", ARRAY_A        
     159               3 :                                         );                                                                      
     160               3 :             $row = $courseData[0];                                                                              
     161               3 :             $course = $row["Name"];                                                                             
     162               3 :             $courseType = $row["Type"];                                                                         
     163                 :         }                                                                                                       
     164                 :                                                                                                                 
     165               3 :         foreach ($data as $row) {                                                                               
     166               3 :             $bbcode = new BBCode(true, false, false);                                                           
     167               3 :             $this->checkCourse($row);                                                                           
     168                 :                                                                                                                 
     169               3 :             if ($prevThreadId == $row['threadid']) {                                                            
     170               0 :                 $doItArray = $this->doIt($row, $pdf);                                                           
     171               0 :                 extract($doItArray);                                                                            
     172               0 :                 $prevThreadId = $row['threadid'];                                                               
     173               0 :             } else {                                                                                            
     174                 :                                                                                                                 
     175               3 :                 if (! $this->firstPageWritten) {                                                                
     176               3 :                     $prefix="";                                                                                 
     177                 :                     switch($courseType){                                                                        
     178               3 :                         case "ecom":                                                                            
     179               0 :                             $prefix = "eCommunity:";                                                            
     180               0 :                             break;                                                                              
     181               3 :                         case "course":                                                                          
     182               3 :                             $prefix = "Kurs:";                                                                  
     183               3 :                             break;                                                                              
     184                 :                     }                                                                                           
     185               3 :                     $getCourse = sprintf(                                                                       
     186               3 :                              $this->translate->_($prefix." %1\$s"),                                             
     187               3 :                              $coursename = $newPdf->getCourse()                                                 
     188               3 :                     );                                                                                          
     189               3 :                     $this->drawCourse($pdf, $getCourse);                                                        
     190               3 :                     $pdf->Ln();                                                                                 
     191               3 :                     $this->firstPageWritten = true;                                                             
     192               3 :                 }                                                                                               
     193               3 :                 if ($this->lastBoard != $row['boardname']) {                                                    
     194               3 :                     $boardname = sprintf(                                                                       
     195               3 :                                  $this->translate->_("Album: %1\$s"),                                           
     196               3 :                                  $boardname = $row['boardname']                                                 
     197               3 :                                  );                                                                             
     198               3 :                     $this->drawCourse($pdf, $boardname);                                                        
     199               3 :                     $pdf->Ln();                                                                                 
     200               3 :                     $this->lastBoard = $row['boardname'];                                                       
     201               3 :                 }                                                                                               
     202                 :                                                                                                                 
     203               3 :                 if ($this->isBoard || (isset ( $row['boarddescription'] ) && $row['boarddescription'] != "")) { 
     204                 :                                                                                                                 
     205               2 :                     if ($this->isBoard) {                                                                       
     206               1 :                         $this->isBoard = false;                                                                 
     207               1 :                         $board = sprintf(                                                                       
     208               1 :                                  $this->translate->_(" Boardbeschreibung: %1\$s"),                              
     209               1 :                                  $boardDesc = $bbcode->parse($this->boardDesc)                                  
     210               1 :                                  );                                                                             
     211               1 :                         $this->drawCourse($pdf, $board);                                                        
     212               1 :                     } else {                                                                                    
     213                 :                                                                                                                 
     214               1 :                         if ($this->lastBoardDesc != $row['boarddescription']) {                                 
     215               1 :                             $board = sprintf(                                                                   
     216               1 :                                      $this->translate->_(" Boardbeschreibung: %1\$s"),                          
     217               1 :                                      $boarddescription = $row['boarddescription']                               
     218               1 :                                      );                                                                         
     219               1 :                             $this->drawCourse($pdf, $board);                                                    
     220               1 :                             $pdf->Ln();                                                                         
     221               1 :                             $this->lastBoardDesc = $row['boarddescription'];                                    
     222               1 :                         }                                                                                       
     223                 :                     }                                                                                           
     224               2 :                     $pdf->Ln();                                                                                 
     225               2 :                     $pdf->Ln();                                                                                 
     226               2 :                 }                                                                                               
     227               3 :                 $theme = sprintf(                                                                               
     228               3 :                          $this->translate->_("Thema: %1\$s"),                                                   
     229               3 :                          $threadtopic = $bbcode->parse($row['threadtopic'])                                     
     230               3 :                          );                                                                                     
     231               3 :                 $this->drawTitle($pdf, $theme);                                                                 
     232               3 :                 $doItArray = $this->doIt($row, $pdf);                                                           
     233               3 :                 extract($doItArray);                                                                            
     234               3 :                 $prevThreadId = $row['threadid'];                                                               
     235                 :             }                                                                                                   
     236               3 :             $prevThreadId = $row['threadid'];                                                                   
     237               3 :         }                                                                                                       
     238               3 :         ob_end_clean();                                                                                         
     239               3 :         $newPdf->getOutput($pdf);                                                                               
     240               3 :     }                                                                                                           
     241                 :                                                                                                                 
     242                 :     private function doIt($row, $pdf) {                                                                         
     243               3 :         global $settings;                                                                                       
     244               3 :         $date = "";                                                                                             
     245                 :         //    $date = new Zend_Date($row['posttime'], $this->locale);                                           
     246               3 :         $bbcode = new BBCode(true, true, true);                                                                 
     247               3 :         $name = sprintf(                                                                                        
     248               3 :                 $this->translate->_("Autor: %1\$s %2\$s"),                                                      
     249               3 :                 $firstname = $bbcode->parse($row['Vorname']),                                                   
     250               3 :                 $lastname = $bbcode->parse($row['Nachname']),                                                   
     251                 :                 $date                                                                                           
     252               3 :                 );                                                                                              
     253               3 :         $this->drawPostingInfo($pdf, $name, $date);                                                             
     254                 :         // Hier kommt die Bildausgabe hin                                                                       
     255               3 :         $ext = strrchr($row['postfilename'], '.');                                                              
     256               3 :         $picPath = PATH_TO_ROOT.$settings["upload_path"].'forum/course/'.$_SESSION['course'];                   
     257               3 :         $picPath = $picPath.'/board/'.$row['boardid'].'/'.$row['postfilesavename'];                             
     258                 :                                                                                                                 
     259                 :         //Achtung: Bilddateien werden ohne endung auf dem Server abgelegt.                                      
     260                 :         //            TCPDF akzeptiert keine Pfadangabe zu einer datei ohne Endung.                             
     261                 :         //            TCPDF meldet in diesem Fall einen Fehler                                                  
     262                 :         //            Um diesen Fehler zu umgehen wird die entsprechende Bilddatei Kopiert und                  
     263                 :         //            der Kopie wird die zugehorige endung angehängt.                                          
     264                 :         //            Anschliessen wird die Kopie geladen (Nun kann man die Pfadangabe mit andung angeben),     
     265                 :         //            nach dem ladne wird die Kopie wider gelöscht.                                            
     266               3 :         if (!is_dir($picPath.$ext))                                                                             
     267               3 :         {                                                                                                       
     268               3 :         copy($picPath,$picPath.$ext);                                                                           
     269               3 :         $this->drawImage($pdf,$picPath.$ext);                                                                   
     270               3 :         unlink($picPath.$ext);                                                                                  
     271               3 :         }                                                                                                       
     272                 :                                                                                                                 
     273                 :                                                                                                                 
     274               3 :         $text = $bbcode->parse($row['posttext']);                                                               
     275               3 :         $this->drawText($pdf, $text);                                                                           
     276               3 :         $pdf->Ln();                                                                                             
     277               3 :         $pdf->lastPage();                                                                                       
     278                 :                                                                                                                 
     279               3 :         $doItArray = array('pdf' => $pdf);                                                                      
     280               3 :         return $doItArray;                                                                                      
     281                 :     }                                                                                                           
     282                 :                                                                                                                 
     283                 :     public function checkCourse($row) {                                                                         
     284               4 :         if ($_SESSION['course'] != $row['categoryid']) {                                                        
     285               1 :             echo "<table>";                                                                                     
     286               1 :             echo Output::errorMessage($this->translate->_("Fehler. Sie sind in diesem Kurs nicht zugelassen."));
     287               1 :             echo "</table>";                                                                                    
     288                 :         //    exit();                                                                                           
     289               1 :         }                                                                                                       
     290               4 :     }                                                                                                           
     291                 :                                                                                                                 
     292                 :     public function checkData($data) {                                                                          
     293               4 :         if (sizeof($data) == 0) {                                                                               
     294               1 :             echo "<table>";                                                                                     
     295               1 :             echo Output::errorMessage($this->translate->_("Fehler. Keine Daten vorhanden."));                   
     296               1 :             echo "</table>";                                                                                    
     297                 :         //    exit();                                                                                           
     298               1 :         }                                                                                                       
     299               4 :     }                                                                                                           

Generated by PHPUnit 3.2.21 and Xdebug 2.0.3 at Sun Dec 27 23:47:06 CET 2009.